package com.myschool.controller;

import com.myschool.entity.Subject;
import com.myschool.service.SubjectService;
import com.myschool.util.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/subject")
public class SubjectController {

    @Autowired
    SubjectService subjectService;

    @RequestMapping("/all")
    public ResponseEntity getAll(){
        ResponseEntity responseEntity = new ResponseEntity();
        responseEntity.setData(subjectService.getAll());
        return responseEntity;
    }

    @RequestMapping("/one/{subjectNo}")
    public ResponseEntity getOne(@PathVariable("subjectNo") Integer subjectNo){
        ResponseEntity responseEntity = new ResponseEntity();
        responseEntity.setData(subjectService.getOne(subjectNo));
        return responseEntity;
    }

    @PostMapping("/add")
    public ResponseEntity add(Subject subject){
        subjectService.add(subject);
        ResponseEntity responseEntity = new ResponseEntity();
        return responseEntity;
    }

    @PostMapping("/update")
    public ResponseEntity update(Subject subject){
        subjectService.update(subject);
        ResponseEntity responseEntity = new ResponseEntity();
        return responseEntity;
    }

    @GetMapping("/delete/{subjectNo}")
    public ResponseEntity delete(@PathVariable("subjectNo") Integer subjectNo){
        subjectService.delete(subjectNo);
        ResponseEntity responseEntity = new ResponseEntity();
        return responseEntity;
    }
}
